<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
    tr_X
</style>
<body class="gray-bg">
<style>
    .fixed-table-body{
        height: calc(73vh);
    }

    .fixed-table-footer{
        border-top: 0;
    }
</style>
<div class="">
    <div class="container-div">
        <div  id="flexSearchBox"  class="collapse out col-sm-12 search-box">
            <form id="user-form">
                <div class="select-list">
                    <ul>
                        <li class="time">
                            <label>Order Date:</label>
                            <input type="text" id="startTime" class="time-input reset"  placeholder="start date" name="beginOrderDate"/>
                            <span>to</span>
                            <input type="text" id="endTime" class="time-input reset"  placeholder="end date" name="endOrderDate"/>
                        </li>
                        <li>
                            Order ID：<input class="reset" type="text" name="orderID"/>
                        </li>
                        <li>
                            SKU：<input class="reset" type="text" name="unitSKUs"/>
                        </li>
                        <li class="time">
                            <label>Update Date:</label>
                            <input type="text" id="startTime1" class="time-input reset"  placeholder="start date" name="beginConfirmedDate"/>
                            <span>to</span>
                            <input type="text" id="endTime1" class="time-input reset"  placeholder="end date" name="endConfirmedDate"/>
                        </li>
                        <li>
                            AWB：<input class="reset" type="text" name="aWB"/>
                        </li>
                        <li shiro:hasPermission="module:allOrder:companySearch">
                            company：<select class="reset_select" id="selCompanyId" name="companyID" >
                            <option th:each="dep : ${depList}" th:text="${dep.deptName}"
                                    th:value="${dep.deptId}"></option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;search</a>
                            <a class="btn btn-primary btn-rounded btn-sm reset-booton"><i class="glyphicon glyphicon-repeat"></i>&nbsp;reset</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group hidden-xs" id="toolbar" role="group">
            <!--<a class="btn btn-outline btn-rounded btn-success " onclick="batchPrintBillAll()" shiro:hasPermission="module:allOrder:print">
                <i class="fa fa-print"></i> batch print
            </a>-->
            <a class="btn btn-outline btn-info btn-rounded flex-botton" data-toggle="collapse" data-target="#flexSearchBox">
                <i class="glyphicon glyphicon-chevron-down">unfoldSearch
                </i>
            </a>
        </div>

        <div class="col-sm-12 select-info table-responsive">
            <table id="bootstrap-table" class="table text-nowrap" data-height="770" data-mobile-responsive="true"></table>
        </div>

        <div  id="batchPrint_div" style="">
            <img src='' class='img-responsive' id="batchPrintFaceBill" />
            <div style='page-break-after:always;'></div>
            <img src='' class='img-responsive' id='batchPrintBill' />
        </div>
    </div>

</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "module/allOrder";
    var editFlag = [[${@permission.hasPermi('module:allOrder:faceBill')}]];
    var orderStateDict = [[${@dict.getType('erp_order_status')}]];//订单状态value转label
    var companyDict = [[${@dict.getType('erp_company')}]];//公司id转name

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "订单详情",
            showFooter:true,
            columns: [{
                checkbox: true,

            },
                {
                    field : 'id',
                    title : 'ID',
                    visible: false
                },
                {
                    title: 'serialNumber',

                    formatter: function (value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                    },
                    footerFormatter: function (value) {
                        return 'total';
                    }
                },
                {
                    title: 'operation',
                    clickToSelect : false,

                    formatter: function(value, row, index) {
                        var actions = [];
                        if((row.surfaceBillUrl!='' && row.surfaceBillUrl!=null) || (row.sendBillUrl!='' && row.sendBillUrl!=null)) {
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="uploadModal(\'' + row.id + '\')"><i class="glyphicon glyphicon-zoom-in"></i>faceBill</a> ');
                        }
                        return actions.join('');
                    }
                },
                {
                    field : 'orderDate',
                    title : 'Order Date',
                    sortable: true,

                },
                {
                    field:'orderID',//订单id

                    title:'<span class="globalSearch_column">Order Id</span>',
                },
                {
                    field : 'orderStatus',//订单状态
                    title : 'Order Status',

                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderStateDict, value);
                    }
                },
                {
                    field : 'lastStatus',//订单上个状态
                    title : 'Last Status',
                    sortable: true,

                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderStateDict, value);
                    }
                },
                {
                    field : 'ofItems',//商品数量
                    title : '# ofItems',
                    sortable: true,

                    footerFormatter: function (value) {
                        return calculateLineTotalAsServer(value,$.table.sumRows.ofItems);
                    }
                },
                {
                    field : 'totalHandlingTime',//处理时长
                    title : 'Total Handing Time',
                    sortable: true,

                },
                {
                    field : 'awb',//航空货运单
                    title : 'AWB',

                },
                {
                    field : 'courier',//快递
                    title : 'Courier',

                },
                {
                    field : 'itemCollectionType',//商品类型
                    title : 'Item Collection Type',
                    sortable: true,

                },
                {
                    field : 'totalShippingFees',//总运送费
                    title : 'Total Shipping Fees',
                    sortable: true,

                    footerFormatter: function (value) {
                        return calculateLineTotalAsServer(value,$.table.sumRows.totalShippingFees);
                    }
                },
                {
                    field : 'paidBySeller',//卖家付款
                    title : 'Paid By Seller',
                    sortable: true,

                    footerFormatter: function (value) {
                        return calculateLineTotalAsServer(value,$.table.sumRows.paidBySeller);
                    }
                },
                {
                    field : 'paymentMethod',//支付方式
                    title : 'Payment Method',
                    sortable: true,

                },
                {
                    field : 'codfee',//货到付款费用
                    title : 'Cod Fee',
                    sortable: true,

                    footerFormatter: function (value) {
                        return calculateLineTotalAsServer(value,$.table.sumRows.codfee);
                    }
                },
                {
                    field : 'isPaid',//是否支付
                    title : 'Is Paid',
                    sortable: true,

                },
                {
                    field : 'paymentReleaseDate',//付款日期
                    title : 'Payment Release Date',
                    sortable: true,

                },
                {
                    field : 'confirmedDate',//确认日期
                    title : 'Confirmed Date',
                    sortable: true,

                },
                {
                    field : 'shippedDate',//发货日期
                    title : 'Shipped Date',
                    sortable: true,

                },
                {
                    field : 'deliveryDate',//交货日期
                    title : 'Delivery Date',
                    sortable: true,

                },
                {
                    field : 'orderAge',//订单耗费时长
                    title : 'Order Age',
                    sortable: true,

                },
                {
                    field : 'shippedAge',//发货耗费时长
                    title : 'Shipped Age',
                    sortable: true,

                },
                {
                    field : 'deliveryAge',//交货耗费时长
                    title : 'Delivery Age',
                    sortable: true,

                },
                {
                    field : 'grandTotal',//总计
                    title : 'Grand Total',
                    sortable: true,

                    footerFormatter: function (value) {
                        return calculateLineTotalAsServer(value,$.table.sumRows.grandTotal);
                    }
                },
                {
                    field : 'unitSKUs',
                    title:'<span class="globalSearch_column">unitSKUs</span>',

                },
                {
                    field:'updateDate',//修改时间（缺省上传时间）
                    title:'<span class="globalSearch_column">lastOperationTime</span>',
                    sortable: true,

                },
                {
                    field : 'companyName',
                    title : 'company',

                },
            ],
            onLoadSuccess: function (item, $element) {
                $('.fixed-table-footer').addClass("totalRowBackground-color");//合计行添加颜色
            },
        };
        $.table.init(options);
    });
</script>
<script th:src="@{/ajax/libs/jquery-migrate/jQuery.print.min.js}"></script>
<script th:src="@{/ruoyi/js/common.js}"></script>
<script>


    function uploadModal(id){
        var url = prefix+"/allOrderFaceBill/"+id;
        $.modal.open("查看面单", url);
    }


    /**
     * 批量打印面单收货单
     */
    function batchPrintBillAll() {
        var batchPrint_div = $("#batchPrint_div");
        //获取选中行
        var getSelectRows = $("#bootstrap-table").bootstrapTable('getSelections', function (row) {
            return row;
        });
        var ids = [];//选中行的id数组

        if(getSelectRows.length==0){
            $.modal.alertWarning("Please select at least one record");
            return false;
        }

        //添加选中行的图片路径
        $("#batchPrintBill").attr("src",getSelectRows[0].sendBillUrl);
        $("#batchPrintFaceBill").attr("src",getSelectRows[0].surfaceBillUrl);

        for (var i =0;i<getSelectRows.length;i++){
            ids.push(getSelectRows[i].id);//获取选中行的id
            if(getSelectRows[i].sendBillUrl==null||getSelectRows[i].surfaceBillUrl==null){
                $.modal.alertWarning("Selected bills include unuploaded surfaceBill or sendBill！");
                batchPrint_div.html("<img src='' class='img-responsive' id='batchPrintBill' />\n" +
                    "            <div style='page-break-after:always;'></div>\n" +
                    "            <img src='' class='img-responsive' id=\"batchPrintFaceBill\" />")
                return false;
            }
            if(i>0){
                batchPrint_div.append("<div style='page-break-after:always;'></div>");
                batchPrint_div.append("<img src=\""+getSelectRows[i].sendBillUrl+"\", class='img-responsive'  />");
                batchPrint_div.append("<div style='page-break-after:always;'></div>");
                batchPrint_div.append("<img src=\""+getSelectRows[i].surfaceBillUrl+"\" class='img-responsive'  />");
            }
        }

        //jquery打印方法
        batchPrint_div.print({
            //是否读取页面的样式
            globalStyles: true,
            //添加与attrbute media=打印的链接。
            mediaPrint: false,
            //在隐藏的iframe中打印。
            iframe: true,
            //不打印 的内容（选择器）
            noPrintSelector: ".avoid-this",
            //在打印的html之前添加内容
            // prepend: "Hello World!!!<br/>",
            //在打印的html之后添加内容,这里添加的直接可以是jquery元素
            // append:aa.html(),
            //在window.print()调用后resolve一个jQuery.Deferred对象
            deferred: $.Deferred().done(function () {
                $.ajax({
                    url:prefix+'/batchUpdateByPrint',
                    dataType:'json',
                    type:'post',
                    data:{
                        ids:ids,
                        sign:"print",
                    },
                    success:function (data) {
                        // window.location.reload();
                        $.table.refresh();
                    },
                    complete: function(XMLHttpRequest, textStatus) {
                    }
                });
            })
        });

        batchPrint_div.html("<img src='' class='img-responsive' id='batchPrintBill' />\n" +
            "            <div style='page-break-after:always;'></div>\n" +
            "            <img src='' class='img-responsive' id=\"batchPrintFaceBill\" />")

    }
</script>
</body>
</html>